package com.wx.mp.config;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 添加响应统一请求头
 * 
 * Copyright: Copyright (c) 2017  zteits
 * 
 * @ClassName: ResponseHeaderFilter.java
 * @Description: 
 * @version: v1.0.0
 * Modification History:
 */
public class ResponseHeaderFilter implements Filter {
	
	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
		HttpServletResponse res = (HttpServletResponse) response;
		res.addHeader("Access-Control-Allow-Origin", "*");
		res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
		res.addHeader("Access-Control-Allow-Headers", "Content-Type, X-Auth-Token, x-requested-with ,Authorization");
		chain.doFilter(request, response);
	}
	
	@Override
	public void destroy() {
	}
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}
}
